﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using PMSGSC.BLL;
using PMSGSC.Common;

namespace PMSGSC.App
{
    public partial class frmFilterCounter : DevExpress.XtraEditors.XtraForm
    {
        public frmFilterCounter(frmMain main)
        {
            InitializeComponent();
            objMain = main;
        }
        private static void LoadSkinToForm()
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.LookAndFeel.DefaultLookAndFeel obj = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            try
            {
                LookAndFeelSettings.Load("LookAndFeelSettings.dat");
            }
            catch
            {
                obj.LookAndFeel.SetSkinStyle("Blue");
            }
        }
        frmMain objMain;
        private void btnOK_Click(object sender, EventArgs e)
        {
            frmProcessBar pb = new frmProcessBar();
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                LoadSkinToForm();
                pb.ShowDialog();
            }
            ));
            thread.Start();

            List<Equipment> equipments;
            if (ucLoadEquipment1.lbid.Text != "")
                equipments = Equipment_BLL.GetCounterTypeEquipment(int.Parse(ucLoadEquipment1.lbid.Text));
            else
                equipments = Equipment_BLL.GetCounterTypeEquipment(0);

            if (equipments.Count != 0)
            {
                frmUpdateCounter updateCounter = new frmUpdateCounter(equipments);
                updateCounter.MdiParent = objMain;
                updateCounter.Show();

                if (pb.InvokeRequired)
                {
                    pb.BeginInvoke(new Action(() => pb.Close()));
                }
                this.Close();
            }
            else
            {
                if (pb.InvokeRequired)
                {
                    pb.BeginInvoke(new Action(() => pb.Close()));
                }
                XtraMessageBox.Show("Not result show display", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
                
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}